************************************************
***Title: robustness_leave_one_out.do
***Creators: Joelle Abramowitz, Shooshan Danagoulian, and Owen Fleming*
***Notes: This file produces the figures for the leave-one-out analyses. The file produces two figures: one in which we iteratively leave out measurement counties, and another in which we iteratively leave out all counties.

*For questions, contact
*Owen Fleming
*hg3490@wayne.edu
************************************************


**********SETUP
use data/for_analysis, clear

*Define macros
levelsof county_measurement
global county_meas_levels = r(levels)

levelsof county
global county_levels = r(levels)


**********PRODUCE ESTIMATES: MEASUREMENT COUNTIES
ppmlhdfe count pollen_q2_ls pollen_q3_ls pollen_q4_ls $weather, absorb(county year_month month_day) cluster(county) tolerance(1e-06)
scalar b = _b[pollen_q4_ls]
scalar se = _se[pollen_q4_ls]
matrix full = b \ se
matrix colnames full = "Baseline"

foreach i in $county_meas_levels {
ppmlhdfe count pollen_q2_ls pollen_q3_ls pollen_q4_ls $weather if county_measurement != `i', absorb(county year_month month_day) cluster(county) tolerance(1e-06)
scalar b_`i' = _b[pollen_q4_ls]
scalar se_`i' = _se[pollen_q4_ls]	
}

foreach i in $county_meas_levels {
matrix bse_`i' = `=b_`i'' \ `=se_`i''
matrix colnames bse_`i' = "name_`i'"
}

foreach i in $county_meas_levels {
	matrix full = full , bse_`i'
}

collapse (first) countyname_measurement, by(county_measurement)

matrix colnames full = "Baseline" ///
                       "Alameda, CA" ///
		       "Contra Costa, CA" ///
		       "Santa Clara, CA" ///
		       "El Paso, CO" ///
		       "New Haven, CT" ///
		       "New Castle, DE" ///
		       "Cobb, GA" ///
		       "Twin Falls, ID" ///
		       "Cook, IL" ///
		       "Jefferson, KY" ///
		       "Montgomery, MD" ///
		       "Baltimore City, MD" ///
		       "Hennepin, MN" ///
		       "Jackson, MO" ///
		       "St. Louis, MO" ///
		       "Douglas, NE" ///
		       "Sarpy, NE" ///		       		       		       
		       "Cattaraugus, NY" ///		       
		       "Monroe, NY" ///
		       "New York, NY" ///
		       "Buncombe, NC" ///
		       "Mecklenburg, NC" ///		       		      		       
		       "Coshocton, OH" ///
		       "Montgomery, OH" ///
		       "Vinton, OH" ///
		       "Oklahoma, OK" ///
		       "Tulsa, OK" ///
		       "Lane, OR" ///
		       "Multnomah, OR" ///
		       "Erie, PA" ///
		       "York, PA" ///
		       "Greenville, SC" ///
		       "Salt Lake, UT" ///
		       "King, WA" ///
		       "La Crosse, WI" 

		       
**********PRODUCE VISUALIZATION: MEASUREMENT COUNTIES		       
coefplot (matrix(full), keep(Baseline) se(2) p1(msymbol(D)) mcolor(red) ciopts(color(red))) (matrix(full), drop(Baseline) se(2) p1(msymbol(D)) mcolor(ebblue) ciopts(color(ebblue))), vertical yline(0) xsize(10) ysize(6) graphregion(color(white)) legend(rows(1) pos(6) region(lstyle(solid))) xlabel(, angle(vertical)) leg(off) xtitle("County dropped from analysis") ytitle("4th Quartile Estimate")
graph export results/robustness_leave_one_out_meas.png, replace


**********PRODUCE ESTIMATES: ALL COUNTIES
ppmlhdfe count pollen_q2_ls pollen_q3_ls pollen_q4_ls $weather, absorb(county year_month month_day) cluster(county) tolerance(1e-06)
scalar b = _b[pollen_q4_ls]
scalar se = _se[pollen_q4_ls]
matrix full = b \ se
matrix colnames full = "Baseline"

foreach i in $county_levels {
ppmlhdfe count pollen_q2_ls pollen_q3_ls pollen_q4_ls $weather if county != `i', absorb(county year_month month_day) cluster(county) tolerance(1e-06)
scalar b_`i' = _b[pollen_q4_ls]
scalar se_`i' = _se[pollen_q4_ls]	
}

foreach i in $county_levels {
matrix bse_`i' = `=b_`i'' \ `=se_`i''
matrix colnames bse_`i' = "name_`i'"
}

foreach i in $county_levels {
	matrix full = full , bse_`i'
}


**********PRODUCE VISUALIZATION AND EXPORT: ALL COUNTIES
coefplot (matrix(full), se(2) p1(msymbol(O)) mcolor(black) ciopts(color(dimgray))), vertical xsize(10) ysize(6) graphregion(color(white)) legend(rows(1) pos(6) region(lstyle(solid))) leg(off) xlabel(none) xtitle("County dropped from analysis") ytitle("4th Quartile Estimate")
graph export results/robustness_leave_one_out_all.png, replace




